package tpo.vista.empleados;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import tpo.controlador.Sistema;

public class AltaAlquilerConReserva extends JFrame {
	
	private Sistema sistema;
	
	public AltaAlquilerConReserva(Sistema sistema) {
		super("Alta Alquiler en base a reserva");
		this.sistema = sistema;
		init();
		setVisible(true);
	}

	private void init() {
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLayout(new GridBagLayout());
		GridBagConstraints gc = new GridBagConstraints();
		
		JLabel labelReserva = new JLabel("Numero Reserva");
		JLabel labelInspeccion = new JLabel("Inspeccion");
		final JTextField fieldReserva = new JTextField("");
		final JTextField fieldInspeccion = new JTextField("");
		JButton button = new JButton("Crear");
		
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evento) {
				try {
					sistema.registrarAlquiler(Integer.parseInt(fieldReserva.getText()),
							fieldInspeccion.getText());
					dispose();
					System.out.println("Se ha creado la reserva.");
				} catch (Exception e) {
					System.out.println("Error al crear reserva.");
					e.printStackTrace();
				}
			}			
		});
		
		gc.gridx = 0;	// Columna
		gc.gridy = 0;	// Fila
		add(labelReserva, gc);		
		gc.gridx = 1;
		gc.gridy = 0;
		fieldReserva.setColumns(10);
		add(fieldReserva, gc);
		
		gc.gridx = 0;
		gc.gridy = 1;
		add(labelInspeccion, gc);		
		gc.gridx = 1;
		gc.gridy = 1;
		fieldInspeccion.setColumns(10);
		add(fieldInspeccion, gc);
		
		gc.gridx = 0;
		gc.gridy = 2;
		add(button, gc);

		pack();
		setSize(400, 300);
	}
}
